﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ProjectStudy.App_Code;
using System.Data.SqlClient;
using System.Drawing;

namespace ProjectStudy.注册登录找回密码修改密码页面
{
    public partial class LeftMenu : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                string sql = "select * from Menu where userGroup=@group";
                SqlParameter ps = new SqlParameter("@group",SysSession.UserGroup.ConvertObjToStr());
                DataTable dt = DBAccess.ExecuteDataTable(sql,ps);
                TreeNode rootNode;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["fatherId"].ConvertObjToStr() == "0")
                    {
                        rootNode = new TreeNode();
                        rootNode.NavigateUrl = dt.Rows[i]["url"].ConvertObjToStr();

                        rootNode.Text =(i+1)+"."+ dt.Rows[i]["menuName"].ConvertObjToStr();
                        rootNode.Value = dt.Rows[i]["menuId"].ConvertObjToStr();
                        rootNode.Target = "content";
                        rootNode.Expanded = false;
                        //rootNode.ImageUrl = "../images/close20.png";
                        //TreeView1.ForeColor = Color.White;
                        TreeView1.Nodes.Add(rootNode);
                        CreateChildNode(rootNode,dt);                     
                    }      
                }
            }
        }

        protected void CreateChildNode(TreeNode fatherNode, DataTable dt)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["fatherId"].ConvertObjToStr() == fatherNode.Value)
                {
                    TreeNode node = new TreeNode();
                    node.Text = (i + 1) + "." + dt.Rows[i]["menuName"].ToString();
                    node.Value = dt.Rows[i]["menuId"].ToString();
                    node.NavigateUrl = dt.Rows[i]["url"].ConvertObjToStr();
                    node.Target = "content";
                    node.Expanded = false;
                    //node.Selected = false;
                    //node.SelectAction = TreeNodeSelectAction.None;
                    fatherNode.ChildNodes.Add(node);
                    CreateChildNode(node, dt); //递归调用
                }
            }

           
        }
    }
}